import appConfig from "../config/index.js";
import request from "uview-ui/libs/request";

request.setConfig({
	baseUrl: appConfig.apiHost + appConfig.apiApi,
	loadingText: '加载中...',
	loadingTime: 800,
	// 设置自定义头部content-type
	header: {
		"Content-Type": "application/json"
	}
});

// 请求拦截器
request.interceptor.request = (config) => {
	if (config.url == '/user/login') {
		config.header.authorization = 'null';
	} else {
		config.header.authorization = "Bearer xxxx";
	}
	return config;
}

// 相应拦截器
request.interceptor.response = (res) => {
	console.log('res', res)
	if (res.statusCode === 401) {
		uni.navigateTo({
			url: "/pages/login/login"
		});
		return false;
	}
	return res
}

export default request;
